<template>
  <div class="dashboard-container">
    <div id="line-charts" style="height: 400px;"></div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import * as echarts from 'echarts'
export default {
  name: 'Dashboard',
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.initLineCharts()
  },
  beforeDestroy() {
    this.destroyChart()
  },
  methods: {
    initLineCharts() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = echarts.init(document.getElementById('line-charts'))
      // 使用option进行第一次初始化
      const option = {
        title: {
          text: '标题'
        },
        tooltip: {},
        xAxis: {
          data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子']
        },
        yAxis: {},
        series: [
          {
            name: '销量',
            type: 'bar',
            data: [20, 30, 50, 60, 70, 80]
          }
        ]
      }
      this.chart.setOption(option)
    },
    // 销毁chart实例
    destroyChart() {
      if (this.chart) {
        this.chart.dispose()
        this.chart = null
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
